<template>
  <div>

    <el-form :inline="true" :model="form" :rules="rules" ref="form" size="mini" style="margin-bottom: -18px;">

      <el-form-item label="查询日期" prop="regDate">
        <el-date-picker v-model="form.regDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd" type="date">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="单位">
        <el-select v-model="form.schoolName" placeholder="请选择单位" filterable>
          <el-option-group v-for="group in options" :key="group.label" :label="group.label">
            <el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-option-group>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button @click="handleFormSubmit">
          <d2-icon name="search" />
          查询
        </el-button>
      </el-form-item>

      <el-form-item>
        <el-button @click="handleFormReset">
          <d2-icon name="refresh" />
          重置
        </el-button>
      </el-form-item>

    </el-form>
  </div>
</template>

<script>
  import {
    jsonData
  } from '@api/demo.jsondata.table.1'
  export default {
    mounted() {
      this.options = jsonData();

      this.getCurrentDate();
    },
    props: {
      dialogFormVisible: {
        default: false
      }
    },
    data() {
      return {
        options: [],
        form: {
          regDate: '',
          schoolName: ''
        },
        rules: {
          regDate: [{
            required: true,
            message: '请选择一个日期',
            trigger: 'change'
          }]
        }
      }
    },
    methods: {

      getCurrentDate() {
        var date = new Date()
        var month = parseInt(date.getMonth() + 1)
        var day = date.getDate()
        if (month < 10) month = '0' + month
        if (day < 10) day = '0' + day
        this.form.regDate = date.getFullYear() + '-' + month + '-' + day
      },
      handleFormSubmit() {
        this.$refs.form.validate((valid) => {
          if (valid) {
            this.$emit('submit', this.form)
          } else {
            this.$notify.error({
              title: '错误',
              message: '表单校验失败'
            })
            return false
          }
        })
      },
      handleFormReset() {
        this.$refs.form.resetFields()
      }
    }
  }
</script>
